package com.ecar.api.service.temp.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.jaxb.SpringDataJaxb.OrderDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.ecar.api.rest.pay.PayController;
import com.ecar.api.service.common.ModelSetService;
import com.ecar.api.service.driver.DriverService;
import com.ecar.api.service.order.OrderPriceDetailService;
import com.ecar.api.service.order.OrderService;
import com.ecar.api.service.temp.BaseInfoService;
import com.ecar.api.support.util.DateUtil;
import com.ecar.api.support.util.Props;
import com.ecar.api.support.util.RandomUtil;
import com.ecar.api.support.util.TempHttpUtil;
import com.ecar.api.support.util.UserUtil;
import com.ecar.api.support.util.WilddogUtil;
import com.ecar.core.common.entity.User;

import com.ecar.core.driver.entity.Driver;

import com.ecar.core.driver.dao.CarMapper;
import com.ecar.core.driver.entity.Car;

import com.ecar.core.order.entity.Order;

import com.ecar.core.passenger.dao.PaymentCommentMapper;
import com.ecar.core.passenger.entity.PaymentComment;

import com.ecar.core.order.entity.OrderPriceDetail;
import com.wilddog.client.DataSnapshot;
import com.wilddog.client.SyncError;
import com.wilddog.client.SyncReference;
import com.wilddog.client.ValueEventListener;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


@Service
@Transactional
public class BaseInfoServiceImpl implements BaseInfoService {
	
	private static Logger log = LoggerFactory.getLogger(BaseInfoServiceImpl.class);

	@Autowired
	OrderService orderService;

	@Autowired
	PaymentCommentMapper paymentCommentMapper;

	@Autowired
	DriverService driverService;

	@Autowired
	OrderPriceDetailService orderPriceDetailService;

	@Autowired
	CarMapper carMapper;

	@Autowired
	ModelSetService modelSetService;

	/**1.网约车平台公司基本信息**/
	@Override
	public void company() {
		String url="/baseinfo/company";

		Map<String, Object> map = new HashMap<String, Object>();
		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("CompanyName", "湖北公路客运集团股份有限公司");
		map.put("Identifier", "914201007071711375");
		map.put("Address", 420107);
		map.put("BusinessScope", "汽车配件、建筑装饰材料的批零兼营；以下经营范围限持许可证的分支机构经营:客运站经营；货运代办；一类（大中型客车维修）；仓储服务；汽车（不含小汽车）销售；住宿、餐饮服务；预包装食品销售；物业管理；房屋租赁服务；国内广告的设计、制作、代理；汽车租赁；市际班车客运、省际班车客运、市际包车客运、省际包车客运；货物运输保险、机动车辆保险、团体人身意外伤害保险、意外伤害保险；乳制品（不含婴幼儿配方乳粉）、散装食品、书刊零售（仅限持证的分支机构经营）；其他日用品、日用百货零售、公用电话服务；市内公共汽车客运（仅限持证的分支机构经营）；国内快递（邮政企业专营业务除外）（限分支机构经营）；房地产开发、新能源开发、停车场服务、成品油销售（仅限分支机构经营）。（上述许可经营项目经营期限与许可证核定的期限一致）（依法须经批准的项目，经相关部门批准后方可开展经营活动）");
		map.put("ContactAddress", "武汉市青山区友谊大道999号A座9楼");
		//map.put("EconomicType", "股份有限公司（非上市、国有控股）");
		map.put("EconomicType", "160");
		map.put("RegCapital", "壹亿伍仟万元整");
		map.put("LegalName", "车用祥");
		map.put("LegalPhone", "13707112160");
		map.put("LegalID", "420103196111023230");
		map.put("State", 0);
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int a=TempHttpUtil.sendPost_JSON(url, map, "baseInfoCompany");
		log.info("===1.网约车平台公司基本信息="+a+"============");

	}

	/**2.网约车平台公司营运规模信息**/
	@Override
	public void companystat(){

		String url="/baseinfo/companystat";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("VehicleNum", 20);
		map.put("DriverNum", 20);
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int a=TempHttpUtil.sendPost_JSON(url, map, "baseInfoCompanyStat");
		log.info("====2.网约车平台公司营运规模信息=="+a+"============");
	}

	/**3.网约车平台公司支付信息**/
	@Override
	public void companypay(){

		String url="/baseinfo/companypay";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("PayName", "银行支付");
		map.put("PayId", "");
		map.put("PayType", "银行转账");
		map.put("PayScope", "网约车");
		map.put("PrepareBank", "中信银行");
		map.put("CountDate", 1);
		map.put("State", 0);
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int a=TempHttpUtil.sendPost_JSON(url, map, "baseInfoCompanyPay");
		log.info("====3.网约车平台公司支付信息===="+a+"============");

	}

	/**4.网约车平台公司服务机构**/
	@Override
	public void companyservice() {

		String url="/baseinfo/companyservice";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("Address", 420107);
		map.put("ServiceName", "湖北公路客运集团股份有限公司");
		map.put("ServiceNo", "914201007071711375");
		map.put("DetailAddress", "武汉市青山区友谊大道999号A座9楼");
		map.put("ResponsibleName", "李青松");
		map.put("ResponsiblePhone", "18971181159");
		map.put("ManagerName", "李青松");
		map.put("ManagerPhone", "18971181159");
		map.put("MailAddress", "武汉市青山区友谊大道999号A座9楼");
		map.put("CreateDate", 19980406L);
		map.put("State", 1);
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int a= TempHttpUtil.sendPost_JSON(url, map, "baseInfoCompanyService");
		log.info("====4.网约车平台公司服务机构==="+a+"============");

	}

	/**5.网约车平台公司经营许可**/
	@Override
	public void companypermit(){

		String url="/baseinfo/companypermit";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("Address", 420107);
		map.put("Certificate", "aaa");
		map.put("OperationArea", "武汉市青山区友谊大道999号A座9楼");
		map.put("OwnerName", "湖北公路客运集团股份有限公司");
		map.put("Organization", "aaa");
		map.put("StartDate", 19980406L);
		map.put("StopDate", 20200201L);
		map.put("CertifyDate", 19980406L);
		map.put("State","1");
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int a=TempHttpUtil.sendPost_JSON(url, map, "baseInfoCompanyPermit");
		log.info("===5.网约车平台公司经营许可==="+a+"============");

	}



	/**6.网约车平台公司运价信息**/
	@Override
	public void companyfare() {


		String url="/baseinfo/companyfare";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("Address", 420107);
		map.put("FareType", "001");
		map.put("FareValidOn", 201802020000L);
		map.put("StartFare", 15);
		map.put("StartMile", 3);
		map.put("UnitPricePerMile", 2.8);
		map.put("UnitPricePerMinute", 0.7);
		map.put("MorningPeakTimeOn", "0700");
		map.put("MorningPeakTimeOff", "2200");
		map.put("EveningPeakTimeOn", "1600");
		map.put("EveningPeakTimeOff", "2100");
		map.put("PeakUnitPrice", 15);
		map.put("PeakPriceStartMile", 15);
		map.put("State", 1);
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int a= TempHttpUtil.sendPost_JSON(url, map, "baseInfoCompanyFare");
		log.info("====6.网约车平台公司运价信息=="+a+"============");

	}


	/**7.车辆基本信息*/
	public void companyvehicle() {

		String url="/baseinfo/vehicle";

		JSONArray  array = new JSONArray();


		String VehicleNo="鄂A1Q1S3#鄂A5PG57#鄂A17W9Q#鄂A9XU17#鄂A1P5R0#鄂A1Q3S9#鄂A5P0B9#鄂A5RB53#鄂A5XB52#鄂A7Q1B7#鄂A7P5J9#鄂A8VM61#鄂A9P2K2#鄂A9P8K6#鄂A15W9G#鄂A50W1#鄂A71R2N#鄂A79W7C#鄂A83W9Y#鄂A7Q0Z3";

		String VehicleNo_arr[] = VehicleNo.split("#");

		String EngineId ="2066E745#2148E762#2141E744#2076E742#2246E741#2071E745#2052E753#2175E732#2046E750#2174E744#2262E749#2178E732#2066E742#2261E741#2158E744#2076E764#2253E729#2021E743#2002E741#2222E733";

		String EngineId_arr[] = EngineId.split("#");

		String VIN="LSYAABCS3FK082510#LSYAABCS2GK024275#LSYAABCS0FK082853#LSYAABCS1FK082747#LSYAABCS1FK082859#LSYAABCS3FK080837#LSYAABCS2GK015995#LSYAABCS8FK082860#LSYAABCS3GK024219#LSYAABCS7FK082672#LSYAABCS7GK024241#LSYAABCS4FK082855#LSYAABCS3FK082877#LSYAABCS9FK082804#LSYAABCS0FK082755#LSYAABCS4FK082712#LSYAABCS7FK082171#LSYAABCS3FK082524#LSYAABCS8FK082289#LSYAABCS9FK082785";

		String VIN_arr[] = VIN.split("#");
		int pk=0;
		for(int i=0;VehicleNo_arr.length>i;i++) {
			pk++;
			
			JSONObject object = new JSONObject();

			String companyId=Props.getValue("ecar.companyId");	
			object.put("CompanyId", companyId);
			object.put("Address", 420107);
			object.put("VehicleNo", VehicleNo_arr[i]);
			object.put("PlateColor", "9");
			object.put("Seats", 7);
			object.put("Brand", "华颂牌");
			object.put("Model", "SY6503S1Z1BG");
			object.put("VehicleType", "小型普通客车");
			object.put("OwnerName", "华颂汽车租赁有限公司关山分公司");
			object.put("VehicleColor", "棕色");
			object.put("EngineId", EngineId_arr[i]);
			object.put("VIN", VIN_arr[i]);
			object.put("CertifyDateA", 20171203);
			object.put("FuelType", "A");
			object.put("EngineDisplace", "2.00");
			object.put("TransAgency", "aa");
			object.put("TransArea", "全国");
			object.put("TransDateStart", 20171201);
			object.put("TransDateStop", 20200201);//??
			object.put("CertifyDateB", 20171201);
			object.put("FixState", "1");
			object.put("CheckState", "1");
			object.put("FeePrintId", "aa");
			object.put("GPSBrand", "aa");
			object.put("GPSModel", "C6D");
			object.put("GPSInstallDate", 20171223);
			object.put("RegisterDate", 20171223);
			object.put("CommercialType", 1);
			object.put("FareType", "001");
			object.put("State", 0);
			object.put("Flag", 1);
			object.put("UpdateTime",Long.parseLong(DateUtil.getCurDateTime1()));

			array.add(object);
		}
		int a=TempHttpUtil.sendPost_JSON(url, array, "baseInfoVehicle");
		log.info("第七条共推送{}条数据",pk);
		log.info("=====7.车辆基本信息=="+a+"============");
	}


	/**8.车辆保险信息*/
	public void companyvehicleinsurance(){

		String url="/baseinfo/vehicleinsurance";

		String VehicleNo="鄂A1Q1S3#鄂A5PG57#鄂A17W9Q#鄂A9XU17#鄂A1P5R0#鄂A1Q3S9#鄂A5P0B9#鄂A5RB53#鄂A5XB52#鄂A7Q1B7#鄂A7P5J9#鄂A8VM61#鄂A9P2K2#鄂A9P8K6#鄂A15W9G#鄂A50W1E#鄂A71R2N#鄂A79W7C#鄂A83W9Y#鄂A7Q0Z3";

		String VehicleNo_arr[] = VehicleNo.split("#");

		String InsurNum="20590942010117000000#20590942010117021335#20590942010117021360#20590942010117021362#20501942010117020012#20501942010117020004#20501942010117019988#20501942010117020023#20501942010117020026#20501942010117019984#20501942010117019989#20501942010117020024#20501942010117020011#20501942010117019993#20501942010117019997#20501942010117019992#20501942010117020013#20501942010117020007#20501942010117019991#20501942010117019987";

		String InsurNum_arr[]=InsurNum.split("#");

		JSONArray  array = new JSONArray();
		int pk=0;
		for(int i=0;VehicleNo_arr.length>i;i++) {
			pk++;
			
			
			JSONObject map = new JSONObject();

			String companyId=Props.getValue("ecar.companyId");	
			map.put("CompanyId", companyId);
			map.put("VehicleNo", VehicleNo_arr[i]);
			map.put("InsurCom", "紫金财保");
			map.put("InsurNum", InsurNum_arr[i]);
			map.put("InsurType", "商业保险");
			map.put("InsurCount", 6407.23);
			map.put("InsurEff", 20171220);
			map.put("InsurExp", 20181219);		
			map.put("Flag", 1);
			map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));
			array.add(map);
		}

		int a=TempHttpUtil.sendPost_JSON(url, array, "baseInfoVehicleInsurance");
		log.info("第8条共推送{}条数据",pk);
		log.info("====8.车辆保险信息==="+a+"============");

	}



	/**14.乘客基本信息*/
	public void passenger(){
		String url="/baseinfo/passenger";
		List<Order> list=orderService.selectTodayOrder();
		JSONArray  array = new JSONArray();
		int pk=0;
		for(Order order:list){
			pk++;
			
			User user=UserUtil.getUserByPhone(order.getPassengerPhone());
			JSONObject baseInfoCompanyFare = new JSONObject();
			String companyId=Props.getValue("ecar.companyId");	
			baseInfoCompanyFare.put("CompanyId", companyId);
			//baseInfoCompanyFare.put("RegisterDate", Long.parseLong(DateUtil.parseDateToString(user==null?new Date():user.getCreateTime(), DateUtil.DATE_FORMAT_COMPACT)));
			baseInfoCompanyFare.put("PassengerPhone", user==null?"11111111111":user.getPhone());
			/*baseInfoCompanyFare.put("PassengerName", companyId);
			baseInfoCompanyFare.put("PassengerGender", companyId);*/
			baseInfoCompanyFare.put("State", 1);
			baseInfoCompanyFare.put("Flag", 2);
			baseInfoCompanyFare.put("UpdateTime", Long.parseLong(DateUtil.parseDateToString(new Date(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			array.add(baseInfoCompanyFare);
		}
		int a=TempHttpUtil.sendPost_JSON(url, array, "baseInfoPassenger");
		log.info("第14条共推送{}条数据",pk);
		log.info("===14.乘客基本信息==="+a+"============");
	}


	/**18.车辆经营上线**//*
	@Override
	public void operateLoginInfo(){

		String url="/operate/login";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");
		map.put("CompanyId", companyId);
		map.put("OrderId", "");
		map.put("LicenseId", "");
		map.put("VehicleNo", "");
		map.put("LoginTime", "");
		map.put("Longitude", "");
		map.put("Latitude", "");
		map.put("Encrypt", "");

		TempHttpUtil.sendPost_JSON(url, map, "operateLogin");

	}

	*//**19.车辆经营下线**//*
	@Override
	public void operateLogoutInfo(){

		String url="/operate/logout";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");
		map.put("CompanyId", companyId);
		map.put("OrderId", "");
		map.put("LicenseId", "");
		map.put("VehicleNo", "");
		map.put("LogoutTime", "");
		map.put("Longitude", "");
		map.put("Latitude", "");
		map.put("Encrypt", "");

		TempHttpUtil.sendPost_JSON(url, map, "operateLogout");

	}


	*//**20.经营出发信息**//*
	@Override
	public void operateDepartInfo(){

		String url="/operate/depart";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");
		map.put("CompanyId", companyId);
		map.put("OrderId", "");
		map.put("LicenseId", "");
		map.put("FareType", "");
		map.put("VehicleNo", "");
		map.put("DepLongitude", "");
		map.put("DepLatitude", "");
		map.put("Encrypt", "");
		map.put("DepTime", "");
		map.put("WaitMile", "");
		map.put("WaitTime", "");

		TempHttpUtil.sendPost_JSON(url, map, "operateDepart");

	}


	*//**21.经营到达信息**//*
	@Override
	public void operateArriveInfo(){

		String url="/operate/arrive";

		Map<String, Object> map = new HashMap<String, Object>();

		String companyId=Props.getValue("ecar.companyId");
		map.put("CompanyId", companyId);
		map.put("OrderId", "");
		map.put("DestLongitude", "");
		map.put("DestLatitude", "");
		map.put("DestArea", "");
		map.put("DestTime", "");
		map.put("DriveMile", "");
		map.put("DriveTime", "");

		TempHttpUtil.sendPost_JSON(url, map, "operateArrive");

	}
*/

	/**22.经营支付信息**/
	@Override
	public void operatePayInfo(){
		String url="/operate/pay";
		List<Order> list = orderService.selectTodayOrder();
		JSONArray  array = new JSONArray();
		int pk=0;
		for(Order order:list){
			
			if(order.getOrderStatus()==6){
				pk++;
				Driver driver=driverService.selectByPrimaryKey(order.getDriverId());
				Car car=carMapper.selectByDriverId(order.getDriverId());
				OrderPriceDetail orderPriceDetail=orderPriceDetailService.selectByOrderNum(order.getOrderNum());
				JSONObject operatePay = new JSONObject();
				String companyId=Props.getValue("ecar.companyId");
				operatePay.put("CompanyId", companyId);
				operatePay.put("OrderId", order.getOrderNum());
				operatePay.put("OnArea", 1);
				/*operatePay.put("DriverName", "");*/
				operatePay.put("LicenseId", driver.getLicenseId());
				operatePay.put("FareType", "运价类编码");
				operatePay.put("VehicleNo", car.getNumberPlate());
				operatePay.put("BookDepTime", Long.parseLong(DateUtil.parseDateToString(order.getPlanTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
				/*operatePay.put("WaitTime", "");*/

				String des=order.getStartLocation();
				String [] dess=des.split(":");
				dess[0]=dess[0].concat("000000");
				dess[1]=dess[1].concat("000000");
				String lon=dess[0].substring(0, 9);
				String lat=dess[1].substring(0, 10);

				operatePay.put("DepLongitude", Long.parseLong(lon.replace(".", "")));
				operatePay.put("DepLatitude", Long.parseLong(lat.replace(".", "")));
				/*operatePay.put("DepArea", "");*/
				operatePay.put("DepTime", Long.parseLong(DateUtil.parseDateToString(order.getStartTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
				String end=order.getDesLocation();
				String [] ends=end.split(":");
				ends[0]=ends[0].concat("000000");
				ends[1]=ends[1].concat("000000");
				lon=ends[0].substring(0, 9);
				lat=ends[1].substring(0, 10);

				operatePay.put("DestLongitude", Long.parseLong(lon.replace(".", "")));
				operatePay.put("DestLatitude", Long.parseLong(lat.replace(".", "")));
				/*operatePay.put("DestArea", "");*/
				operatePay.put("DestTime", Long.parseLong(DateUtil.parseDateToString(order.getEndTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
				/*operatePay.put("BookModel", "");
			operatePay.put("Model", "");*/
				operatePay.put("DriveMile", orderPriceDetail.getRoadDistance());
				long time=DateUtil.timeMinus(order.getEndTime(), order.getStartTime());
				operatePay.put("DriveTime", time/1000);
				/*operatePay.put("WaitMile", "");*/
				operatePay.put("FactPrice", order.getActualPrice());
				/*operatePay.put("Price", "");
			operatePay.put("CashPrice", "");
			operatePay.put("LineName", "");
			operatePay.put("LinePrice", "");*/
				/*operatePay.put("PosName", "");
			operatePay.put("PosPrice", "");
			operatePay.put("BenfitPrice", "");
			operatePay.put("BookTip", "");
			operatePay.put("PassengerTip", "");
			operatePay.put("PeakUpPrice", "");
			operatePay.put("NightUpPrice", "");*/
				operatePay.put("FarUpPrice", orderPriceDetail.getLightDriverPrice());
				operatePay.put("OtherUpPrice", orderPriceDetail.getAddCharge());
				operatePay.put("PayState", order.getPayStatus()==1?"0":"1");
				/*operatePay.put("PayTime", "");
			operatePay.put("OrderMatchTime", "");*/
				operatePay.put("InvoiceStatus", "0");
				array.add(operatePay);
			}
		}
		int i=TempHttpUtil.sendPost_JSON(url, array, "operatePay");
		log.info("第22条共推送{}条数据",pk);
		log.info("==22.经营支付信息==="+i+"=========");
	}


	/**23.驾驶员定位信息**/
	@Override
	public void positionDriverInfo(){
		final String url="/position/driver";
		final JSONArray  array = new JSONArray();
		SyncReference driverRef=WilddogUtil.getDriverRef("WilddogLocation/map");
		driverRef.addListenerForSingleValueEvent(new ValueEventListener() {
			@Override
			public void onDataChange(DataSnapshot dataSnapshot) {
				Iterator<DataSnapshot> iterator=dataSnapshot.getChildren().iterator();
				int pk=0;
				while(iterator.hasNext()){
					pk++;
					
					JSONObject positionDriver = new JSONObject();
					DataSnapshot driverDataSnapshot=iterator.next();
					String driverId=driverDataSnapshot.getKey();
					Driver driver=driverService.selectByPrimaryKey(driverId);
					if(driver==null){
						continue;
					}
					Car car=carMapper.selectByDriverId(driverId);
					String companyId=Props.getValue("ecar.companyId");
					positionDriver.put("CompanyId", companyId);
					
					positionDriver.put("LicenseId", driver.getLicenseId()==null?"111111":driver.getLicenseId());
					positionDriver.put("DriverRegionCode", 420107);
					positionDriver.put("VehicleNo", car.getNumberPlate());
					long time=(long) driverDataSnapshot.child("timestamp").getValue();
					positionDriver.put("PositionTime", time);
					Double lon=(Double) driverDataSnapshot.child("location/0").getValue();
					Double lat=(Double) driverDataSnapshot.child("location/1").getValue();
					String aa=lon+""+"0000";
					String bb=lat+""+"0000";
					String alon=aa.substring(0, 9).replace(".", "");
					String alat=bb.substring(0, 10).replace(".", "");
					
					positionDriver.put("Longitude", Long.parseLong(alon));
					positionDriver.put("Latitude", Long.parseLong(alat));
					
					
					positionDriver.put("Encrypt", 0);
					positionDriver.put("Direction", 0);
					positionDriver.put("Elevation", 0);
					positionDriver.put("Speed", 0);
					positionDriver.put("BizStatus", 2);
					
					positionDriver.put("OrderId", "0");
					array.add(positionDriver);
				}
				int i=TempHttpUtil.sendPost_JSON(url, array, "positionDriver");
				log.info("第23条共推送{}条数据",pk);
				log.info("===23.驾驶员定位信息==="+i+"==============");


			}
			@Override
			public void onCancelled(SyncError arg0) {
			}
		});



	}


	/**24.车辆定位信息**/
	//获取当天的在运行的订单
	@Override
	public void positionVehicleInfo(){
		final List<Order> list=orderService.selectWorkingOrderToday();
		SyncReference driverRef=WilddogUtil.getDriverRef("WilddogLocation/map");
		driverRef.addListenerForSingleValueEvent(new ValueEventListener() {
			@Override
			public void onDataChange(DataSnapshot dataSnapshot) {
				log.info("list============"+list.size());
				String url="/position/vehicle";
				JSONArray  array = new JSONArray();
				int pk=0;
				for(Order order:list){
					pk++;
					
					JSONObject positionVehicle = new JSONObject();
					Car car=carMapper.selectByDriverId(order.getDriverId());
					String companyId=Props.getValue("ecar.companyId");
					positionVehicle.put("CompanyId", companyId);
					positionVehicle.put("VehicleNo", car.getNumberPlate());
					positionVehicle.put("VehicleRegionCode", 420107);
					
					long time = (long) dataSnapshot.child(order.getDriverId()).child("timestamp").getValue();
					
					positionVehicle.put("PositionTime", time);
					
					Double lon=(Double) dataSnapshot.child(order.getDriverId()).child("location").child("0").getValue();
					Double lat=(Double) dataSnapshot.child(order.getDriverId()).child("location").child("1").getValue();
					
					lon=lon+0.000000;
					lat=lat+0.000000;
					String alon=lon.toString().substring(0, 9).replace(".", "");
					String alat=lat.toString().substring(0, 10).replace(".", "");
					
					positionVehicle.put("Longitude", Long.parseLong(alon));
					positionVehicle.put("Latitude", Long.parseLong(alat));
					/*positionVehicle.put("Speed", "");
					positionVehicle.put("Direction", "");
					positionVehicle.put("Elevation", "");
					positionVehicle.put("Mileage", "");
					positionVehicle.put("Encrypt", "");
					positionVehicle.put("WarnStatus", "");
					positionVehicle.put("VehStatus", "");
					positionVehicle.put("BizStatus", "");*/
					positionVehicle.put("OrderId", order.getOrderNum());
					array.add(positionVehicle);
				}
				int i=TempHttpUtil.sendPost_JSON(url, array, "positionVehicle");
				log.info("第24条共推送{}条数据",pk);
				log.info("===24.车辆定位信息===="+i+"==========");
			}
			@Override
			public void onCancelled(SyncError arg0) {
			}
		});
	}


	/**25.乘客评价信息**/
	@Override
	public void passagengerEvaluateInfo(){

		String url="/rated/passenger";

		JSONArray  array = new JSONArray();

		List<PaymentComment> list = paymentCommentMapper.select();
		int pk=0;
		for(PaymentComment pc: list) {
			pk++;
			
			JSONObject map = new JSONObject();

			String companyId=Props.getValue("ecar.companyId");
			map.put("CompanyId", companyId);
			map.put("OrderId", pc.getOrderNo());
			map.put("EvaluateTime", Long.parseLong(DateUtil.parseDateToString(pc.getCreateTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("ServiceScore", pc.getRate());
			map.put("DriverScore", pc.getRate());
			map.put("VehicleScore", pc.getRate());
			map.put("Detail", pc.getCommentContent());

			array.add(map);

		}

		int i=TempHttpUtil.sendPost_JSON(url, array, "ratedPassenger");
		log.info("第25条共推送{}条数据",pk);
		log.info("===25.乘客评价信息=="+i+"==========");

	}



	/**26.乘客投诉信息**/
	@Override
	public void passengerComplaintInfo(){

		String url="/rated/passengercomplaint";

		JSONArray  array = new JSONArray();
		
		List<PaymentComment> list = paymentCommentMapper.select();
        int pk=0;
		for(PaymentComment pc: list) {
			pk++;
			
			JSONObject map = new JSONObject();
			String companyId=Props.getValue("ecar.companyId");
			map.put("CompanyId", companyId);
			map.put("OrderId", pc.getOrderNo());
			map.put("ComplaintTime", Long.parseLong(DateUtil.parseDateToString(pc.getCreateTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("Detail", "无意见");
			//map.put("Result", pc.getRate()+"");
			
			array.add(map);
			
		}
		
		int i=TempHttpUtil.sendPost_JSON(url, array, "ratedPassengerComplaint");
		log.info("第26条共推送{}条数据",pk);
		log.info("==26.乘客投诉信息=="+i+"==========");

	}

	
	/**
	 * 31,私人小客车合乘订单
	 */
	@Override
	public void shareOrder() {
		String url="/share/order";
		JSONArray  array = new JSONArray();
		
		List<Order> list = orderService.selectTodayCarpool();
		int pk=0;
		for(Order order: list) {
			pk++;
			
			JSONObject map = new JSONObject();
			String companyId=Props.getValue("ecar.companyId");
			map.put("CompanyId", companyId);
			map.put("Address", 420107);
			map.put("RouteId", order.getParentOrder());
			map.put("OrderId", order.getOrderNum());
			map.put("BookDepartTime", Long.parseLong(DateUtil.parseDateToString(order.getPlanTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("Departure", order.getStartAddress());
			String start=order.getStartLocation();
			String [] starts=start.split(":");
			
			starts[0]=starts[0].concat("000000");
			starts[1]=starts[1].concat("000000");
			String lon=starts[0].substring(0, 9);
			lon=lon.replace(".", "");
			String lat=starts[1].substring(0, 10);
			lat=lat.replace(".", "");
			map.put("DepLongitude", Long.parseLong(lon));
			map.put("DepLatitude", Long.parseLong(lat));
			map.put("Destination", order.getDesAddress());
			String des=order.getDesLocation();
			String [] dess=des.split(":");
			
			dess[0]=dess[0].concat("000000");
			dess[1]=dess[1].concat("000000");
			lon=dess[0].substring(0, 9);
			lon=lon.replace(".", "");
			lat=dess[1].substring(0, 10);
			lat=lat.replace(".", "");
			map.put("DestLongitude", Long.parseLong(lon));
			map.put("DestLatitude", Long.parseLong(lat));
			
			map.put("Encrypt", 0);
			map.put("OrderEnsureTime", Long.parseLong(DateUtil.parseDateToString(order.getStartTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("PassengerNum", order.getUseSeats());
			map.put("PassengerNote", "豪华车");
			array.add(map);
		}
		
		int i=TempHttpUtil.sendPost_JSON(url, array, "shareOrder");
		log.info("第31条共推送{}条数据",pk);
		log.info("===31,私人小客车合乘订单=="+i+"==========");
	}

	/**32私人小客车合乘订单支付**/
	public void sharepay() {
		
		String url="/share/pay";
		
		JSONArray  array = new JSONArray();
		
		List<Order> list = orderService.selectTodayCarpool();
		int pk=0;
		for(Order order: list) {
			pk++;
			
			JSONObject map = new JSONObject();
			String companyId=Props.getValue("ecar.companyId");
			map.put("CompanyId", companyId);
			map.put("Address", 420107);
			map.put("RouteId", order.getParentOrder());
			map.put("OrderId", order.getOrderNum());
			Driver driver =driverService.selectByPrimaryKey(order.getDriverId());
			map.put("DriverPhone", driver.getPhone());
			map.put("LicenseId", driver.getLicenseId()==null?"1111111":"1111111");
			Car car = carMapper.selectByDriverId(order.getDriverId());
			map.put("VehicleNo", car.getNumberPlate());
			map.put("FareType", "001");
			map.put("BookDepartTime", Long.parseLong(DateUtil.parseDateToString(order.getPlanTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("DepartTime", Long.parseLong(DateUtil.parseDateToString(order.getStartTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("Departure", order.getStartAddress());
			String start=order.getStartLocation();
			String [] starts=start.split(":");
			starts[0]=starts[0].concat("000000");
			starts[1]=starts[1].concat("000000");
			String lon=starts[0].substring(0, 9);
			lon=lon.replace(".", "");
			String lat=starts[1].substring(0, 10);
			lat=lat.replace(".", "");
			map.put("DepLongitude", Long.parseLong(lon));
			map.put("DepLatitude", Long.parseLong(lat));
			map.put("DestTime", Long.parseLong(DateUtil.parseDateToString(order.getEndTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("Destination", order.getDesAddress());
			String des=order.getDesLocation();
			String [] dess=des.split(":");
			dess[0]=dess[0].concat("000000");
			dess[1]=dess[1].concat("000000");
			
			lon=dess[0].substring(0, 9);
			lon=lon.replace(".", "");
			lat=dess[1].substring(0, 10);
			lat=lat.replace(".", "");
			map.put("DestLongitude", Long.parseLong(lon));
			map.put("DestLatitude", Long.parseLong(lat));
			map.put("Encrypt", 0);
			OrderPriceDetail orderPriceDetail = orderPriceDetailService.selectByOrderNum(order.getOrderNum());
			map.put("DriveMile", orderPriceDetail==null?0:orderPriceDetail.getRoadDistance());
			long time=DateUtil.timeMinus(order.getEndTime(), order.getStartTime());
			map.put("DriveTime", time/1000);			
			map.put("FactPrice", order.getActualPrice());
			map.put("Price", order.getOrderPrice());
			map.put("CashPrice", 0);
			map.put("LineName", "微信支付");
			map.put("LinePrice", order.getActualPrice());
			map.put("BenfitPrice", 0);
			map.put("ShareFuelFee", 0);
			map.put("ShareHighwayToll", 0);
			map.put("PassengerTip", 0);
			map.put("ShareOther", 0);
			map.put("PayState", order.getPayStatus()==1?"0":"1");
			map.put("PassengerNum", 1);
			map.put("PayTime", Long.parseLong(DateUtil.parseDateToString(order.getCreateTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			map.put("OrderMatchTime", Long.parseLong(DateUtil.parseDateToString(order.getEndTime(), DateUtil.DATE_FORMAT_COMPACTFULL)));
			array.add(map);
		}
		
		int i=TempHttpUtil.sendPost_JSON(url, array, "sharePay");
		log.info("第32条共推送{}条数据",pk);
		log.info("===32私人小客车合乘订单支付=="+i+"==========");
		
	}
	
	
    
	/**29.私人小客车合乘信息平台基本信息**/
	@Override
	public void sharecompany() {
		
		String url="/share/company";

		Map<String, Object> map = new HashMap<String, Object>();
		String companyId=Props.getValue("ecar.companyId");	
		map.put("CompanyId", companyId);
		map.put("CompanyName", "湖北公路客运集团股份有限公司");
		map.put("Identifier", "914201007071711375");
		map.put("Address", 420107);
		map.put("BusinessScope", "汽车配件、建筑装饰材料的批零兼营；以下经营范围限持许可证的分支机构经营:客运站经营；货运代办；一类（大中型客车维修）；仓储服务；汽车（不含小汽车）销售；住宿、餐饮服务；预包装食品销售；物业管理；房屋租赁服务；国内广告的设计、制作、代理；汽车租赁；市际班车客运、省际班车客运、市际包车客运、省际包车客运；货物运输保险、机动车辆保险、团体人身意外伤害保险、意外伤害保险；乳制品（不含婴幼儿配方乳粉）、散装食品、书刊零售（仅限持证的分支机构经营）；其他日用品、日用百货零售、公用电话服务；市内公共汽车客运（仅限持证的分支机构经营）；国内快递（邮政企业专营业务除外）（限分支机构经营）；房地产开发、新能源开发、停车场服务、成品油销售（仅限分支机构经营）。（上述许可经营项目经营期限与许可证核定的期限一致）（依法须经批准的项目，经相关部门批准后方可开展经营活动）");
		map.put("ContactAddress", "武汉市青山区友谊大道999号A座9楼");
		map.put("EconomicType", "股份有限公司（非上市、国有控股）");
		map.put("EconomicType", "160");
		map.put("LegalName", "车用祥");
		map.put("LegalPhone", "13707112160");
		map.put("LegalID", "420103196111023230");
		map.put("LegalPhone", "13707112160");
		map.put("State", 0);
		map.put("Flag", 1);
		map.put("UpdateTime", Long.parseLong(DateUtil.getCurDateTime1()));

		int ii=TempHttpUtil.sendPost_JSON(url, map, "shareCompany");
		
		log.info("===29.私人小客车合乘信息平台基本信息=="+ii+"==========");
		
	}


}
